package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import com.itheima.service.HealthItemService;
import com.itheima.service.SetmealService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Reference
    public CheckGroupService checkGroupService;

    @Reference
    public SetmealService setmealService;
	
	
	String a="122334dasfdsgds";

    @Reference
    public HealthItemService healthItemService;

    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return checkGroupService.findList(queryPageBean);
    }

    /**
     * 修改检查组
     * @author cc
     * @param checkGroup
     * @return
     */
    @PostMapping("/edit")
    public Result update(@RequestBody CheckGroup checkGroup){
        return checkGroupService.update(checkGroup);
    }

    @GetMapping("/findById")
    public Result findByid(@RequestParam Integer id){
        return checkGroupService.findById(id);
    }

    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(@RequestParam Integer id){
        final List<CheckItem> checkItemIdsByCheckGroupId = checkGroupService.findCheckItemIdsByCheckGroupId(id);

        return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItemIdsByCheckGroupId);
    }

    /**
     *
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll(){
        List<CheckGroup> all = setmealService.findAll();
        if(CollectionUtils.isEmpty(all)){
            return new Result(false,MessageConstant.QUERY_CHECKGROUP_FAIL);
        }
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,all);
    }

}
